var ws = '';
document.addEventListener('plusready',function(){
	ws = plus.webview.currentWebview(); 
	store_id = plus.storage.getItem('storeid');
	store_name = plus.storage.getItem('store_name');
	avatar = plus.storage.getItem('avatar');
	key = plus.storage.getItem('key');
	$('.avatar').attr('src',avatar?userpic+avatar:"../doc/pic_img.jpg");
	$('.store_name').text(store_name);
	console.log(key+store_id);
	$.ajax({ 
		type:"post",
		url:apiRoot + "?act=seller_order&op=order_list",
		data:{
			key:key,
			state_type:'store_order',
			store_flag:'mobile'
		},
		dataType:'json',
		success:function(data){
			console.log(JSON.stringify(data));
			if(data.code == 200){
				if(data.datas.order_list.length > 0){
					var html_n = html_m = html_l = html_ok = html_r = ''; 
					var num_n = num_m = num_l = num_ok = num_r = 0;
					var zt = '<div style="width: 80%;margin: 40px auto;text-align: center;font-size: 18px;">你还没有数据...</div>';
					$.each(data.datas.order_list, function(key,val) {
						if(val.refund_state > 0){
							num_r++;
							html_r += '<ul class="mui-table-view mui-grid-view marg" onclick="order_details()">';
											$.each(val.goods_list, function(k,v) {
									  html_r += '<li class="mui-table-view-cell mui-col-xs-3">'+
													'<img class="mui-media-object mui-pull-left" src="'+ pics + v.store_id + '/' + v.goods_image +'"/>'+
												'</li>'+
												'<li class="mui-table-view-cell mui-col-xs-9">'+
													'<div class="mui-ellipsis-2">'+ v.goods_name +'</div>	'+									
													'<div class="money">'+
														'<span>￥'+ v.goods_price +'</span>'+
														'<span>x'+ v.goods_num +'</span>'+
													'</div>'+
												'</li>';
											})
								  html_r += '<li class="mui-table-view-cell total">	'+									
												'<span>合计：￥'+ val.order_amount +'</span>'+
												'<span>'+
													'<span class="gray">已退款</span>'+	
												'</span>'+
											'</li>'+
										'</ul>';
						}else if(val.order_state == 10){
							num_n++;
							html_n += '<ul class="mui-table-view mui-grid-view marg" onclick="order_details('+ val.order_sn +')">';
											$.each(val.goods_list, function(k,v) {
									  html_n += '<li class="mui-table-view-cell mui-col-xs-3">'+
													'<img class="mui-media-object mui-pull-left" src="'+ pics + v.store_id + '/' + v.goods_image +'"/>'+
												'</li>'+
												'<li class="mui-table-view-cell mui-col-xs-9">'+
													'<div class="mui-ellipsis-2">'+ v.goods_name +'</div>	'+									
													'<div class="money">'+
														'<span>￥'+ v.goods_price +'</span>'+
														'<span>x'+ v.goods_num +'</span>'+
													'</div>'+
												'</li>';
											})
								  html_n += '<li class="mui-table-view-cell total">	'+									
												'<span>合计：￥'+ val.order_amount +'</span>'+
												'<span>'+
													'<button type="button" class="mui-btn Success">接单</button>'+	
												'</span>'+
											'</li>'+
										'</ul>';
						}else if(val.order_state == 20){
							num_m++;
							html_m += '<ul class="mui-table-view mui-grid-view marg" onclick="order_details('+ val.order_sn +')">';
											$.each(val.goods_list, function(k,v) {
									  html_m += '<li class="mui-table-view-cell mui-col-xs-3">'+
													'<img class="mui-media-object mui-pull-left" src="'+ pics + v.store_id + '/' + v.goods_image +'"/>'+
												'</li>'+
												'<li class="mui-table-view-cell mui-col-xs-9">'+
													'<div class="mui-ellipsis-2">'+ v.goods_name +'</div>	'+									
													'<div class="money">'+
														'<span>￥'+ v.goods_price +'</span>'+
														'<span>x'+ v.goods_num +'</span>'+
													'</div>'+
												'</li>';
											})
								  html_m += '<li class="mui-table-view-cell total">	'+									
												'<span>合计：￥'+ val.order_amount +'</span>'+
												'<span>'+
													'<button type="button" class="mui-btn RGB">配送</button>'+	
												'</span>'+
											'</li>'+
										'</ul>';
						}else if(val.order_state == 30){
							num_l++;
							html_l += '<ul class="mui-table-view mui-grid-view marg" onclick="order_details('+ val.order_sn +')">';
											$.each(val.goods_list, function(k,v) {
									  html_l += '<li class="mui-table-view-cell mui-col-xs-3">'+
													'<img class="mui-media-object mui-pull-left" src="'+ pics + v.store_id + '/' + v.goods_image +'"/>'+
												'</li>'+
												'<li class="mui-table-view-cell mui-col-xs-9">'+
													'<div class="mui-ellipsis-2">'+ v.goods_name +'</div>	'+									
													'<div class="money">'+
														'<span>￥'+ v.goods_price +'</span>'+
														'<span>x'+ v.goods_num +'</span>'+
													'</div>'+
												'</li>';
											})
								  html_l += '<li class="mui-table-view-cell total">	'+									
												'<span>合计：￥'+ val.order_amount +'</span>'+
												'<span>'+
													'<button type="button" class="mui-btn RGB">完成</button>'+	
												'</span>'+
											'</li>'+
										'</ul>';
						}else if(val.order_state == 40){
							num_ok++;
							html_ok += '<ul class="mui-table-view mui-grid-view marg" onclick="order_details('+ val.order_sn +')">';
											$.each(val.goods_list, function(k,v) {
									  html_ok += '<li class="mui-table-view-cell mui-col-xs-3">'+
													'<img class="mui-media-object mui-pull-left" src="'+ pics + v.store_id + '/' + v.goods_image +'"/>'+
												'</li>'+
												'<li class="mui-table-view-cell mui-col-xs-9">'+
													'<div class="mui-ellipsis-2">'+ v.goods_name +'</div>	'+									
													'<div class="money">'+
														'<span>￥'+ v.goods_price +'</span>'+
														'<span>x'+ v.goods_num +'</span>'+
													'</div>'+
												'</li>';
											})
								  html_ok += '<li class="mui-table-view-cell total">'+
												'<span>合计：￥'+ val.order_amount +'</span>'+
												'<span>'+
													'<span class="gray">已完成</span>'+	
												'</span>'+
											'</li>'+
										'</ul>';
						}
					});
					if(num_n > 0){
						$('#item1mobile .mui-scroll').html(html_n);
					}else{
						$('#item1mobile .mui-scroll').html(zt);
					}
					if(num_m > 0){
						$('#item2mobile .mui-scroll').html(html_m);
					}else{
						$('#item2mobile .mui-scroll').html(zt);
					}
					if(num_l > 0){
						$('#item3mobile .mui-scroll').html(html_l);
					}else{
						$('#item3mobile .mui-scroll').html(zt);
					}
					if(num_ok > 0){
						$('#item4mobile .mui-scroll').html(html_ok); 
					}else{
						$('#item4mobile .mui-scroll').html(zt); 
					} 
					if(num_r > 0){
						$('#item5mobile .mui-scroll').html(html_r); 
					}else{
						$('#item5mobile .mui-scroll').html(zt); 
					} 
				}else{
					toast('您还没有订单！');
				}
				
			}else{
				toast(data.datas.error);
			}
		},
		error:function(e){
			error();
		}
	});
//	个人资料
	$(".Personl").on("tap",function(){
		var nwaiting = plus.nativeUI.showWaiting();//显示原生等待框
		var webviewContent= plus.webview.create('./Personal_data.html','Personal_data.html',{},{spage:ws.id});//后台创建webview并打开show.html
		webviewContent.addEventListener("loaded", function() { //注册新webview的载入完成事件
	        nwaiting.close(); //新webview的载入完毕后关闭等待框
	        webviewContent.show("slide-in-right",500); //把新webview窗体显示出来，显示动画效果为速度200毫秒的右侧移入动画
	    }, false);
//		openNewPage('Personal_data.html')
	})
	
},false)
function order_details(order_sn){
	alert(order_sn+'77');return false;
	var nwaiting = plus.nativeUI.showWaiting();//显示原生等待框
	var webviewContent= plus.webview.create('./orders_goods.html','orders_goods.html',{},{order_sn:order_sn});//后台创建webview并打开show.html
	webviewContent.addEventListener("loaded", function() { //注册新webview的载入完成事件
        nwaiting.close(); //新webview的载入完毕后关闭等待框
        webviewContent.show("slide-in-right",500); //把新webview窗体显示出来，显示动画效果为速度200毫秒的右侧移入动画
    }, false);
}

